//--------------------------------------------------------------------//
// Do-file: 03_appendix_results 
//
// Paper: "Mano Dura: An Experimental Evaluation of Military Policing in Cali, 
// Colombia"
//
// Authors: Robert Blair, Lucia Mendoza-Mora, and Michael Weintraub
//
// Date last modified: 2024-12-23
// 
// Notes:
// (1) This code replicates the tables and figures included in the appendix 
// of the paper.
//
//--------------------------------------------------------------------//


			/////////////////////////////////
			//                             //
			// Appendix tables and figures //
			//                             //
			/////////////////////////////////
		
					
//---------//
// -- Preliminaries 
//---------//

clear all
set more off
graph set window fontface "Times New Roman"
set maxvar 20000

* Defining main computer path
global path "[YOUR DIRECTORY]" 
		
* Set working directory
cd "${path}" 

* Set globarl vars
global demovars age gender educ 
global indiv_control age gender
global blockdemovars block_age block_educ block_pct_male 
global geovars number_buildings_sampling area bat_min cai_min ptr_min 
		
* Load functions 
include "code/01_Housekeeping.do"


	
				//----------------------------------------------------//
				//--  Table A1: balance using administrative data   --//
				//----------------------------------------------------//

//- Load data 

	use "data/admin_data_prior.dta", clear
	
	global outcomes_s homicides_num robberies_num drugdeal_num wbearing_num 
	global index unw_crime2_num

//- Generating balance table
	
	gen panel_a = .
	gen panel_b = .
	gen panel_c = .
	gen panel_d = .
		la var panel_a "\textbf{\textit{Panel A: Index without controls}}"
		la var panel_b "\textbf{\textit{Panel B: Components without controls}}"
		la var panel_c "\textbf{\textit{Panel C: Index with controls}}"
		la var panel_d "\textbf{\textit{Panel D: Components with controls}}"
		
	global all $index $outcomes_s
	
	mat coefs = J(`:word count $all'*2+`:word count $geovars'*2+4,6,.) 
												
	mat pvalues = J(rowsof(coefs),colsof(coefs),.)
	mat f = J(7,colsof(coefs)-3,.)	
	mat fpval = f
	
	loc j = 1
	loc jf = 1
	foreach g of varlist control treatment spillover {
	
	*Without controls
	
		qui reg `g' unw_crime2_num i.barrio_code [pweight = iweight]
			mat coefs[2,`j'] = _b[unw_crime2_num]
			mat coefs[2,`j'+1] = _se[unw_crime2_num]
			mat pvalues[2,`j'] = round(2*ttail(e(df_r), abs(_b[unw_crime2_num]/_se[unw_crime2_num])),0.001)		
			
			test unw_crime2_num
			mat f[2,`jf'] = r(F)
			mat fpval[2,`jf'] = r(p)
			
		qui reg `g' $outcomes_s i.barrio_code [pweight = iweight]
			
			loc r = 4
			foreach l in $outcomes_s {
				mat coefs[`r',`j'] = _b[`l']
				mat coefs[`r',`j'+1] = _se[`l']
				mat pvalues[`r',`j'] = round(2*ttail(e(df_r), abs(_b[`l']/_se[`l'])),0.001)		
					loc ++r
			}
			
			test $outcomes_s
			mat f[3,`jf'] = r(F)
			mat fpval[3,`jf'] = r(p)					

	* With controls 
		qui reg `g' unw_crime2_num i.barrio_code $geovars [pweight = iweight]
			
			loc r1 = `r'+1
			foreach l1 in unw_crime2_num $geovars {
				mat coefs[`r1',`j'] = _b[`l1']
				mat coefs[`r1',`j'+1] = _se[`l1']
				mat pvalues[`r1',`j'] = round(2*ttail(e(df_r), abs(_b[`l1']/_se[`l1'])),0.001)		
					loc ++r1
			}
			
			test unw_crime2_num
			mat f[4,`jf'] = r(F)
			mat fpval[4,`jf'] = r(p)

			// index and geo controls together
			test unw_crime2_num $geovars
			mat f[5,`jf'] = r(F)
			mat fpval[5,`jf'] = r(p)
		
		qui reg `g' $outcomes_s i.barrio_code $geovars [pweight = iweight]
			loc r2 = `r1'+1
			foreach l2 in $outcomes_s $geovars {
				mat coefs[`r2',`j'] = _b[`l2']
				mat coefs[`r2',`j'+1] = _se[`l2']
				mat pvalues[`r2',`j'] = round(2*ttail(e(df_r), abs(_b[`l2']/_se[`l2'])),0.001)		
					loc ++r2
			}
		
			test $outcomes_s
			mat f[6,`jf'] = r(F)
			mat fpval[6,`jf'] = r(p)
			
			// Components and geo controls together
			test $outcomes_s $geovars
			mat f[7,`jf'] = r(F)
			mat fpval[7,`jf'] = r(p)
			
		loc j = `j'+2
		loc ++jf

	}
	
	
	count
		mat f[1,1] = r(N)
		mat f[1,2] = r(N)
		mat f[1,3] = r(N)

	mat colnames coefs = Control SE Treatment SE Spillover SE
	mat rownames coefs = panel_a $index panel_b $outcomes_s panel_c $index $geovars panel_d $outcomes_s $geovars

	* Labels for output
	la var unw_crime2_num "unweighted crime index"
	la var homicides_num "Homicides"
	la var robberies_num "Robberies"
	la var drugdeal_num "Drug dealing"
	la var wbearing_num "llegal possession of a firearm"
	la var number_buildings_s "Number of buildings on block"
	la var area "Area of block"
	la var bat_min "Distance to nearest army battalion (meters)"
	la var cai_min "Distance to nearest police station (meters)"
	la var ptr_min "Distance to nearest public transportation hub (meters)"
	
	* Set table for stars - coefficients
	mat stars = J(rowsof(coefs),colsof(coefs),0)
	loc k = colsof(coefs)			
	loc n = rowsof(coefs)
	
	forvalues m = 1/`k' {
		forvalues j = 1/`n' {
			matrix stars[`j',`m'] = (pvalues[`j',`m'] < 0.1) + (pvalues[`j',`m'] < 0.05) + (pvalues[`j',`m'] < 0.01)				
		}
	}
	
	* Export table 		
	frmttable using "results/Balance_admin_data_2024.tex", tex statmat(coefs) ///
		annotate(stars) asymbol(*,**,**) replace fr varlabels sdec(3) substat(1) basefont(normalsize rm) statfont(rm)

	
	* Set table for stars - fstat
	mat starsf = J(rowsof(f),colsof(f),0)
	loc k = colsof(f)			
	loc n = rowsof(f)
	
	forvalues m = 1/`k' {
		forvalues j = 1/`n' {
			matrix starsf[`j',`m'] = (fpval[`j',`m'] < 0.1) + (fpval[`j',`m'] < 0.05) + (fpval[`j',`m'] < 0.01)				
		}
	}

	* Append f stats and observations
	loc ti1 "Observations" 
	loc ti2 "\textbf{Panel A:} F-stat on index without controls"
	loc ti3 "\textbf{Panel B:} F-stat on components without controls"
	loc ti4 "\textbf{Panel C:} F-stat on index"
	loc ti5 "\textbf{Panel C:} F-stat on index with controls"
	loc ti6 "\textbf{Panel D:} F-stat on components"
	loc ti7 "\textbf{Panel D:} F-stat on components with controls"
	
	frmttable using "results/Balance_admin_data_2024.tex", tex statmat(f)  									///
		annotate(starsf) asymbol(*,**,***) fr rtitle("`ti1'" \ "`ti2'" \ "`ti3'" \ "`ti4'" \ "`ti5'" \ "`ti6'" \ "`ti7'") 	///
		sdec(0 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3) append  hlines(11{0}10000001) basefont(normalsize rm) statfont(rm)
						
	
	
				//-----------------------------------------------//
				//--  Table A2: balance using endline survey   --//
				//-----------------------------------------------//
						
//----//
//- Balance of endline data
//----//
	
	use "data/survey_endline.dta", clear	
	
	* For DE
		ta treatment, g(treatment_d)

	* Vars to be tested
		#delim ;
			global demovars age gender educ ;
			global geovars number_buildings_sampling area bat_min cai_min ptr_min ;
			global cvars $demovars $geovars ;
		#delim cr
	
		gen panel_a = .
		gen panel_b = .
			la var panel_a "\textbf{\textit{Panel A: Demographic controls}}"
			la var panel_b "\textbf{\textit{Panel B: Demographic and geo controls}}"

		loc d = `: word count $demovars'
		loc p = `: word count $geovars'
		loc r = `d'+`p'
		
		mat DE = J(`d'*2+`p'+2,6,.)	   				// Demo only, demo + geo 
		mat pvalues = J(rowsof(DE),colsof(DE),.)
		mat f = J(4,colsof(DE)-3,.)	
		mat fpval = f
		
		loc j = 1
		loc jf = 1
		foreach var of varlist treatment_d1 treatment_d2 treatment_d3 {
			
		* Demo controls 
			qui reg `var' $demovars [pweight = iweight], vce(cluster manzana_code)  
				
				loc n = 2
				foreach l in $demovars {
					mat DE[`n',`j'] = _b[`l']
					mat DE[`n',`j'+1] = _se[`l']
					mat pvalues[`n',`j'] = round(2*ttail(e(df_r), abs(_b[`l']/_se[`l'])),0.001)		
						loc ++n
				}

				test $demovars
				mat f[2,`jf'] = r(F)
				mat fpval[2,`jf'] = r(p)					

		* Demo + geo controls 
			qui reg `var' $demovars $geovars [pweight = iweight], vce(cluster manzana_code)  
			
				loc n1 = `n'+1
				foreach l1 in $demovars $geovars {
					mat DE[`n1',`j'] = _b[`l1']
					mat DE[`n1',`j'+1] = _se[`l1']
					mat pvalues[`n1',`j'] = round(2*ttail(e(df_r), abs(_b[`l1']/_se[`l1'])),0.001)
						loc ++n1
				}
				
				// Only demovars
				test $demovars
				mat f[3,`jf'] = r(F)
				mat fpval[3,`jf'] = r(p)					
			
				// Demo + geovars
				test $demovars $geovars
				mat f[4,`jf'] = r(F)
				mat fpval[4,`jf'] = r(p)
				
			loc j = `j'+2 
			loc ++jf
			
				
		}
	
		count 
			mat f[1,1] = r(N)
			mat f[1,2] = r(N)
			mat f[1,3] = r(N)
			
		mat colnames DE = Control SE Treatment SE Spillover SE
		mat rownames DE = panel_a $demovars panel_b $demovars $geovars
	
	* Set table for stars - coefficients
			mat stars = J(rowsof(DE),colsof(DE),0)
			loc k = colsof(DE)			
			loc n = rowsof(DE)
			
			forvalues m = 1/`k' {
				forvalues j = 1/`n' {
					matrix stars[`j',`m'] = (pvalues[`j',`m'] < 0.1) + (pvalues[`j',`m'] < 0.05) + (pvalues[`j',`m'] < 0.01)				
				}
			}
			
	* Labels
		la var age "Age"
		la var gender "Gender"
		la var educ "Education (years)"
		la var number_buildings_sam "Number of buildings on the block"
		la var area "Area of block"
		la var bat_min "Distance to nearest army battalion (meters)" 
		la var cai_min "Distance to nearest police station (meters)" 
		la var ptr_min "Distance to nearest public transportation hub (meters)"

	* Export table 		
		frmttable using "results/balance_endline.tex", tex statmat(DE) 			 ///
				annotate(stars) asymbol(*,**,***) replace fr varlabels sdec(5) substat(1) ///
				basefont(normalsize rm) statfont(rm)
	
	* Set table for stars - fstat
		mat starsf = J(rowsof(f),colsof(f),0)
		loc k = colsof(f)			
		loc n = rowsof(f)
		
		forvalues m = 1/`k' {
			forvalues j = 1/`n' {
				matrix starsf[`j',`m'] = (fpval[`j',`m'] < 0.1) + (fpval[`j',`m'] < 0.05) + (fpval[`j',`m'] < 0.01)				
			}
		}
	
	* Append f stats and observations
		loc ti1 "Observations" 
		loc ti2 "\textbf{Panel A:} F-stat on individual-level controls"
		loc ti3 "\textbf{Panel B:} F-stat on individual-level controls"
		loc ti4 "\textbf{Panel B:} F-stat on individual and block-level controls"
		
		frmttable using "results/balance_endline.tex", tex statmat(f)  			///
			annotate(starsf) asymbol(*,**,***) fr rtitle("`ti1'" \ "`ti2'" \ "`ti3'" \ "`ti4'") 	///
			sdec(0 \ 3 \ 3 \ 3) append  hlines(11{0}10001) basefont(normalsize rm) statfont(rm)
			
	
	
				//---------------------------------------------------//
				//--  Table A3. Descriptive statistics on patrols  --//
				//---------------------------------------------------//

//----//
//- Descriptive stats on patrols from TREATED blocks ONLY
//----//
		
//- First part: Avg stats
	
	use "data/admin_data_during.dta", clear

//- Subset to treatment vars 

	keep if treatment == 1	
	
	* Set vars
		global outcomes n_events mean_mnz_duration_patrol mean_n_patrollers mean_mnz_day_correct
		
	* Define matrix
		loc r = `:word count $outcomes'
		mat de = J(`r',2,.)			// Include SD
		
	* Fill matrix - For all blocks
		loc j = 1	
		foreach x of varlist $outcomes {
			
			if "`x'" != "mnz_day_correct_avg" loc r "r(mean)"
			if "`x'" == "mean_mnz_day_correct" loc r "r(mean)*100"
			* Stats			
				sum `x' 
				mat de[`j',1] = `r'
				mat de[`j',2] = r(sd)
				
					loc ++j
		}
	
		mat rownames de = $outcomes

	* Row labels
		la var n_events 			"Avg. # of patrols per block"
		la var mean_mnz_duration_patrol 	"Avg. length of patrol"
		la var mean_n_patrollers 		"Avg. # of soldiers per patrol"
		la var mean_mnz_day_correct		"Avg. \% of patrols on correct block per night"
	
	* Export 
	
		frmttable using "results/descriptive_patrols_treat", tex statmat(de) substat(1)		///
			replace fr sdec(2) ctitle("","Treated blocks") varlabel basefont(normalsize rm) statfont(rm)

	
//- Second part: % of patrols with at least 1
	
		use "data/patrols_data.dta", clear
	
	* Set vars
		global outcomes1 mnz_frisk_count mnz_idcheck_count mnz_drug_count mnz_arrest_count mnz_reten_count
	
		
	* Define matrix
		loc r = `:word count $outcomes1'
		mat de = J(`r',1,.)
				
		count if mnz_correct_svy == 0 | mnz_correct_svy == 1
		loc tot_mnz_all = r(N)
	
	* Fill matrix - For all blocks
		loc j = 1	
		foreach x of varlist $outcomes1 {
			
			* Part 1: % of patrols with at least 1 _________					
				count if `x' >= 1 & !missing(mnz_correct_svy)
				mat de[`j',1] = (r(N) / `tot_mnz_all')*100
						
					loc ++j
		}
		
		mat rownames de = $outcomes1
		
	* Row labels
		la var mnz_frisk_count 			"\% of patrols with at least 1 frisk"
		la var mnz_idcheck_count 		"\% of patrols with at least 1 ID check"
		la var mnz_drug_count 			"\% of patrols with at least 1 drug seizure"
		la var mnz_arrest_count			"\% of patrols with at least 1 arrest"
		la var mnz_reten_count			"\% of patrols with at least 1 detention"	
		
	* Export 
	
		frmttable using "results/descriptive_patrols_treat", tex statmat(de) 		///
				append fr sdec(3) ctitle("", "Treated blocks") varlabel 			///
				basefont(normalsize rm) statfont(rm)
	


	   	//-------------------------------------------------------------//
		// 	   Table A4. Predictors or non-compliance on spillover     //
		//						and control groups					   //
		//-------------------------------------------------------------//
	
	use "data/admin_data_during.dta", clear
	

//-- Run the regressions 

	reg id_patrol i.barrio_code ${geovars} ${blockdemovars} cum_all_unw_crime2_num [pweight=iweight] if treatment != 1
	
	qui sum id_patrol if treatment != 1
	estadd scalar c_mean = r(mean), replace
	estadd scalar f_stat = e(F), replace
	
	estimates store reg_patrol 
	
	
//-- Export the regression 

	loc var1 `"\textbf{\shortstack{Prob. of patrol}}"'

	   esttab reg_patrol ///
		using "results\balance_control_spill.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(number_buildings_sampling area bat_min cai_min ptr_min cum_all_unw_crime2_num block_age block_educ block_pct_male) compress ///
		label keep(cum_all_unw_crime2_num number_buildings_sampling area bat_min cai_min ptr_min block_age block_educ block_pct_male) ///
		indicate("Neighborhood FE = *.barrio_code" , labels("\checkmark" "\xmark")) ///
		stats(N r2 c_mean f_stat, fmt(0 3 3 3)  labels("Observations" "\$R^2$" "DV mean" "F-Statistic")) ///
		nonotes nonum nodepvar nogaps mtitle(`"`var1'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	///
		prehead( 													///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}				///
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}}    	/// 
		   \hline \hline    				   						///
		   \noalign{\smallskip} 									///
		   &  \multicolumn{1}{c}{\textbf{\shortstack{Control and spillover \\ blocks }}} \\ ///
		     \noalign{\smallskip}									///
			  \cline{2-2} \addlinespace								///		   
	   \noalign{\smallskip}											///
	   )  															///
	   posthead(\addlinespace 										///
			\hline 													///
			\addlinespace											///
		) 															///
	   postfoot(  													///
		  \noalign{\smallskip} \hline \hline  						///
		  \end{tabular} 											///
		  \medskip     												///
	   )	
	 	
		
		
	   	//---------------------------------------------------------//
		//			Table A5. Predictors of dosage				   //
		//---------------------------------------------------------//

	use "data/admin_data_during.dta", clear
	

//- Regressions: number of patrols for all blocks 

	reg n_events i.barrio_code ${geovars} ${blockdemovars} cum_all_unw_crime2_num [pweight=iweight]
	
	qui sum n_events 
	estadd scalar c_mean = r(mean), replace
	estadd scalar f_stat = e(F), replace
	
	estimates store reg1

	
//-- Regressions: number of patrols for treament blocks 
	
	reg n_events_treated i.barrio_code ${geovars} ${blockdemovars} cum_all_unw_crime2_num [pweight=iweight]
	
	qui sum n_events_treated 
	estadd scalar c_mean = r(mean), replace
	estadd scalar f_stat = e(F), replace
	
	estimates store reg2
	

//-- Export the regressions number of patrols (for treated and whole sample)
	
	loc var1 `"\textbf{\shortstack{All \\ blocks}}"'
	loc var2 `"\textbf{\shortstack{Treatment \\ blocks}}"'

	   esttab reg1 reg2 ///
		using "results\balance_num_patrols.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(number_buildings_sampling area bat_min cai_min ptr_min cum_all_unw_crime2_num block_age block_educ block_pct_male) compress ///
		label keep(cum_all_unw_crime2_num number_buildings_sampling area bat_min cai_min ptr_min block_age block_educ block_pct_male) ///
		indicate("Neighborhood FE = *.barrio_code" , labels("\checkmark" "\xmark")) ///
		stats(N r2 c_mean f_stat, fmt(0 3 3 3)  labels("Observations" "\$R^2$" "DV mean" "F-Statistic")) ///
		nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	///
		prehead( 													///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}				///
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}}    	/// 
		   \hline \hline    				   						///
		   \noalign{\smallskip} 									///
		   &  \multicolumn{2}{c}{\textbf{Number of patrols}} \\ ///
		     \noalign{\smallskip}									///
			  \cline{2-3} \addlinespace								///		   
	   \noalign{\smallskip}											///
	   )  															///
	   posthead(\addlinespace 										///
			\hline 													///
			\addlinespace											///
		) 															///
	   postfoot(  													///
		  \noalign{\smallskip} \hline \hline  						///
		  \end{tabular} 											///
		  \medskip     												///
	   )
	  		
			
			
			//-------------------------------------------------//
			//		Table A6. Descriptive statistics on 	   //
			//				residents and blocks 			   //
			//-------------------------------------------------//

//-------//
//--  First part: Descriptive statistics for DVs
//-------//
	
	use "data/survey_endline.dta", clear	
	
* Restrict sample to observations used in regressions (with complete variables)

	gen complete_controls=1 if !missing(age, gender, educ, number_buildings_sampling, /*
	*/ area, bat_min, cai_min, ptr_min)
	
	
* Define variables for DVs
	global dvs i_legitpoliceindex_std attitudes_respond_police attitudes_invest_police /*
		*/ attitudes_excessive_police attitudes_corrupt_police attitudes_poor_police /*
		*/ attitudes_race_police attitudes_youth_police attitudes_gender_police /*
		*/ i_legitmilitaryindex_std attitudes_respond_military attitudes_invest_military /*
		*/ attitudes_excessive_military attitudes_corrupt_military attitudes_poor_military /*
		*/ attitudes_race_military attitudes_youth_military attitudes_gender_military /*
		*/ political_ideology1 attitudes_milicoup_crime attitudes_milicoup_corr /*
		*/ attitudes_lawenforcement_std attitudes_commpunish_std age gender educ 

* Define matrix
	local r = `:word count $dvs'
	mat de = J(`r', 5, .)  // 5 columns: Mean, SD, Min, Max, N

* Fill matrix
	local j = 1
	foreach var of varlist $dvs {
		quietly summarize `var' if !missing(`var') & complete_controls==1
		mat de[`j', 1] = r(mean)
		mat de[`j', 2] = r(sd)
		mat de[`j', 3] = r(min)
		mat de[`j', 4] = r(max)
		mat de[`j', 5] = r(N)
		local ++j
	}

	mat rownames de = $dvs

* Row labels
	label var i_legitpoliceindex_std "Perceptions of police"
	label var attitudes_respond_police "Respond promptly"
	label var attitudes_invest_police "Investigate crimes effectively"
	label var attitudes_excessive_police "Use excessive force"
	label var attitudes_corrupt_police "Are corrupt"
	label var attitudes_poor_police "Treat poor and rich equally"
	label var attitudes_race_police "Treat Afro-Colombians and non-Afro-Colombians equally"
	label var attitudes_youth_police "Treat the young and old equally"
	label var attitudes_gender_police "Treat women and men equally"

	label var i_legitmilitaryindex_std "Perceptions of military"
	label var attitudes_respond_military "Respond promptly"
	label var attitudes_invest_military "Investigate crimes effectively"
	label var attitudes_excessive_military "Use excessive force"
	label var attitudes_corrupt_military "Are corrupt"
	label var attitudes_poor_military "Treat poor and rich equally"
	label var attitudes_race_military "Treat Afro-Colombians and non-Afro-Colombians equally"
	label var attitudes_youth_military "Treat the young and old equally"
	label var attitudes_gender_military "Treat women and men equally"


	label var political_ideology1 "Turnout for conservative candidates"
	label var attitudes_milicoup_crime "Support for military coups in response to crime"
	label var attitudes_milicoup_corr "Support for military coups in response to corruption"
	label var attitudes_lawenforcement_std "Support for bypassing the legal system"
	label var attitudes_commpunish_std "Support for vigilante violence"

	label var age "Age"
	label var gender "Gender"
	label var educ "Education (years)"

* Export
frmttable using "results/stats_residents_blocks", tex statmat(de) ///
    substat(0) replace fr sdec(2, 3, 3, 3, 0) ///
	ctitle("", "Mean", "SD", "Min.", "Max.", "N")  ///
    varlabel basefont(normalsize rm) statfont(rm)
 

//-------//
//--  Second part: Descriptive statistics for behavioral data 
//-------//

	use "data/behavioral_data.dta", clear	

	* Define variable for percentage calculation
	global dvs_beha num_report 

	* Define matrix
	local r = `:word count $dvs_beha'
	mat de = J(`r', 5, .)  // 5 columns: Mean, SD, Min, Max, N

	* Fill matrix
	local j = 1
	foreach var of varlist $dvs_beha {
		quietly summarize `var' if !missing(`var')
		mat de[`j', 1] = r(mean)
		mat de[`j', 2] = r(sd)
		mat de[`j', 3] = r(min)
		mat de[`j', 4] = r(max)
		mat de[`j', 5] = r(N)
		local ++j
	}

	mat rownames de = $dvs_beha

	* Row labels
	label variable num_report "Demand for military"

	* Append to the first table
	frmttable using "results/stats_residents_blocks", tex statmat(de) ///
		append fr sdec(2, 3, 3, 3, 0) ///
		ctitle("", "Mean", "SD", "Min.", "Max.", "N")  ///
		varlabel basefont(normalsize rm) statfont(rm)


//-------//
//--  Third part: Descriptive statistics for block-level controls  
//-------//

	use "data/admin_data_during.dta", clear	

	* Define variable for percentage calculation
	global dvs_block $geovars 

	* Define matrix
	local r = `:word count $dvs_block'
	mat de = J(`r', 5, .)  // 5 columns: Mean, SD, Min, Max, N

	* Fill matrix
	local j = 1
	foreach var of varlist $dvs_block {
		quietly summarize `var' if !missing(`var')
		mat de[`j', 1] = r(mean)
		mat de[`j', 2] = r(sd)
		mat de[`j', 3] = r(min)
		mat de[`j', 4] = r(max)
		mat de[`j', 5] = r(N)
		local ++j
	}

	mat rownames de = $dvs_block

	* Row labels
	label variable number_buildings_sampling "Number of buildings on block"
	label variable area "Area of block"
	label variable bat_min "Distance to nearest army battalion (meters)"
	label variable cai_min "Distance to nearest police station (meters)"
	label variable ptr_min "Distance to nearest public transportation hub (meters)"
	
	* Append to the first table
	frmttable using "results/stats_residents_blocks", tex statmat(de) ///
		append fr sdec(2, 3, 3, 3, 0) ///
		ctitle("", "Mean", "SD", "Min.", "Max.", "N")  ///
		varlabel basefont(normalsize rm) statfont(rm)


		
		    //-----------------------------------------------------//
		    //   Table A7: Treatment effects on attitudes towards  //
			//    the police and military and demand for military  //
			//	policing, collapsing spillover and control groups  //
			//-----------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
				

//-- Column 1 (perceptions of the police)	

	reg i_legitp  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitp  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store lpol_a
	
					 
//-- Column 2 (perceptions of the military)	

	reg i_legitm  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitm  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store lmil_a
	

//----//								 
//- Regressions with behavioral addition of endline data	
//----//				

	use "data/behavioral_data.dta", clear			
	
//-- Column 3 (demand for the military)	

	reg num_report i.treatment_d i.barrio_code ${blockdemovars} ${geovars} [pweight = iweight], baselevels
	
	qui sum num_report  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store bha
	

//-- Export the regressions --//
	
	loc var1 `"\textbf{\shortstack{Perceptions of \\ police}}"'
	loc var2 `"\textbf{\shortstack{Perceptions of \\ military}}"'
	loc var3 `"\textbf{\shortstack{Demand for \\ military}}"'

	esttab lpol_a lmil_a bha ///
		using "results\ITT_perceptions_demand_dtreat.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment_d) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment_d) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{2}{c}{\textbf{Survey data}}		   							///
		   & \textbf{Behavioral data} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-3} \cline{4-4} \addlinespace			 											///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )							
		
		
							
		    //-----------------------------------------------------//
		    //   	Table A8: Treatment effects on turnout for 	   //
			//    	right-wing candidates, collapsing spillover    //	
			//					and control groups  			   //
			//-----------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//-- Load data (endline)
					
	use "data/survey_endline.dta", clear	
	
	
//-- Column 1 (turnout for conservative candidates - all)	

	reg political_ideology1  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum political_ideology1  if treatment == 0
	estadd scalar c_mean = r(mean), replace	
	
	estimates store vote1
	

//------//	
//-- Export regressions -original format
//------//
	
		loc p1 "All"
				
		esttab vote1  ///
			using "results\ITT_turnout_dtreat.tex", ///
			legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
			order(treatment_d) compress ///
			indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
			keep(1.treatment_d) ///
			stats(N r2 c_mean, fmt(0 3 3 3) labels("Observations" "\$R^2$" "Control mean")) ///
			label nonotes nonum nodepvars nogaps mtitle(`"`p1'"') ///
			star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 ///
			prehead(  																		///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{1}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-2} \addlinespace			 											///
			&  \multicolumn{1}{c}{\textbf{\shortstack{Turnout for \\ conservative \\ candidates}}} \\			///
			\noalign{\smallskip}																	///
			\cline{2-2}  \addlinespace													///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )					
						
						
						
		    //-----------------------------------------------------//
		    //   	Table A9: Treatment effects on support for 	   //
			//    military coups and extrajudicial punishment,     //	
			//		collapsing spillover and control groups  	   //
			//-----------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//-- Load data (endline)
					
	use "data/survey_endline.dta", clear	
		

//-- Column 1 (supports military coups in response to crime)	

	reg attitudes_milicoup_crime  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_crime  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store coup1
	
	
//-- Column 2 (supports military coups in response to corruption)	

	reg attitudes_milicoup_corr  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_corr  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store coup2
	

//-- Column 3 (survey support for vigilantism)	
		
	reg attitudes_lawenforcement_std  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_lawenforcement_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store vigi

		
//-- Column 4 (survey support for bypassing the police)

	reg attitudes_commpunish_std  i.treatment_d i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_commpunish_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store byp_pol

	
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{In response \\ to crime}}"
	loc var2 "\textbf{\shortstack{In response \\ to corruption}}"
	loc var3 "\textbf{\shortstack{Bypassing the\\ legal system}}"
	loc var4 "\textbf{\shortstack{Bypassing the\\ police}}"

	esttab coup1 coup2 vigi byp_pol ///
		using "results\ITT_vigilante_coups_dtreat.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment_d) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment_d) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"' `"`var4'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{4}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///
			\cline{2-5} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for military coups}}}		///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for vigilantism}}}  \\			///
			\cline{2-3} \cline{4-5} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
			
			
		
				//-----------------------------------------------------//
				//-- 	Table A10: Heterogeneous treatment effects   --//
				// 	   on attitudes towards the police and military    //
				//		and demand for military policing by number 	   //
				//					of patrols 						   //
				//-----------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
	
	
//-- Merge with patrol variables 
	
	gen manzana = manzana_code 
	merge m:1 manzana using "data/admin_data_during.dta" 
	keep if _merge == 3
	
	
//-- Column 1 (perceptions of the police)

	reg i_legitp i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitp  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store lpol_a
	
					 
//-- Column 2 (perceptions of the military)	

	reg i_legitm i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitm  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store lmil_a
	

//----//								 
//- Regressions with behavioral addition of endline data	
//----//				

	use "data/behavioral_data.dta", clear
			
//-- Merge with patrol variables 

	merge m:1 manzana using "data/admin_data_during.dta" 
	keep if _merge == 3
	
	
//-- Column 3 (demand for the military)	

	reg num_report i.treatment##c.n_events i.barrio_code ${blockdemovars} ${geovars} [pweight = iweight], baselevels
	
	qui sum num_report  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store bha
	

//-- Export the regressions --//
	
	loc var1 `"\textbf{\shortstack{Perceptions of \\ police}}"'
	loc var2 `"\textbf{\shortstack{Perceptions of \\ military}}"'
	loc var3 `"\textbf{\shortstack{Demand for \\ military}}"'

	esttab lpol_a lmil_a bha ///
		using "results\ITT_perceptions_demand_het_patrols.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment n_events) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment n_events 1.treatment#c.n_events 2.treatment#c.n_events) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{2}{c}{\textbf{Survey data}}		   							///
		   & \textbf{Behavioral data} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-3} \cline{4-4} \addlinespace			 											///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
	
	
	
				//-----------------------------------------------------//
				//-- 	Table A11: Heterogeneous ITT on turnout      --//
				//	 for right-wing candidates by number of patrols    //
				//-----------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
	
	
//-- Merge with patrol variables 
	
	gen manzana = manzana_code 
	merge m:1 manzana using "data/admin_data_during.dta" 
	keep if _merge == 3

	
//-- Column 1 (turnout for conservative candidates - all)	

	reg political_ideology1  i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum political_ideology1  if treatment == 0
	estadd scalar c_mean = r(mean), replace	
	
	estimates store vote1
	
	
//------//	
//-- Export regressions -original format
//------//
	
		loc p1 "All"
				
		esttab vote1  ///
			using "results\ITT_turnout_conservative_het_patrols.tex", ///
			legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
			order(1.treatment 2.treatment n_events) compress ///
			indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
			keep(1.treatment 2.treatment n_events 1.treatment#c.n_events 2.treatment#c.n_events) ///
			stats(N r2 c_mean, fmt(0 3 3 3) labels("Observations" "\$R^2$" "Control mean")) ///
			label nonotes nonum nodepvars nogaps mtitle(`"`p1'"') ///
			star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 ///
			prehead(  																		///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{1}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-2} \addlinespace			 											///
			&  \multicolumn{1}{c}{\textbf{\shortstack{Turnout for \\ conservative \\ candidates}}}  \\			///
			\noalign{\smallskip}																	///
			\cline{2-2} \addlinespace													///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
							
			
		
				//------------------------------------------------------//
				//-- 	Table A12: Heterogeneous ITT on support       --//
				// 	for military coups and extrajudicial punishment		//
				//			by number of patrols 	   					//
				//------------------------------------------------------//

//----//								 
//- Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
	
	
//-- Merge with patrol variables 
	
	gen manzana = manzana_code 
	merge m:1 manzana using "data/admin_data_during.dta" 
	keep if _merge == 3
					

//-- Column 1 (supports military coups in response to crime)	
	
	reg attitudes_milicoup_crime  i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_crime  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store coup1	
	
	
//-- Column 2 (supports military coups in response to corruption)
	
	reg attitudes_milicoup_corr  i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_corr  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store coup2


//-- Column 3 (survey support for vigilantism)	
		
	reg attitudes_lawenforcement_std  i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_lawenforcement_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store vigi

		
//-- Column 4 (survey support for bypassing the police)
	
	reg attitudes_commpunish_std  i.treatment##c.n_events i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_commpunish_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store byp_pol

	
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{In response \\ to crime}}"
	loc var2 "\textbf{\shortstack{In response \\ to corruption}}"
	loc var3 "\textbf{\shortstack{Bypassing the\\ legal system}}"
	loc var4 "\textbf{\shortstack{Bypassing the\\ police}}"

	esttab coup1 coup2 vigi byp_pol ///
		using "results\ITT_vigilante_coups_het_patrols.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment n_events) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment n_events 1.treatment#c.n_events 2.treatment#c.n_events) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"' `"`var4'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{4}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///
			\cline{2-5} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for military coups}}}		///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for vigilantism}}}  \\			///
			\cline{2-3} \cline{4-5} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )		
							
							
							
			//------------------------------------------------------------//
			//--  Table A13: ITT on perceptions of police and military  --//
			// 		and demand for military policing with RI p-values     //
			//			and multiple comparisons correction 			  //
			//------------------------------------------------------------//
	   
//-------//
//-- Run regressions for randomization inference (endline data)
//-------//

* Run regressions

foreach var in i_legitp i_legitm {
	
	di "*** REGRESSIONS WITH VARIABLE `var' ***"
	
	* Create empty matrix
	matrix treat_effects = J(10000, 2, .)
	matrix colnames treat_effects = treat_ef spillover_ef
	
	
	forvalues n = 1/10000{
	
			use "data/rand_inf/block_simulate_randomizations_p1.dta", clear
				
			*di "This is simulation number `n'"
			
	//- Obtain treatment status of each block 
			keep manzana treatment_ri_`n'
			rename treatment_ri_`n' treatment_ri
			rename manzana manzana_code
			
	//- Merge with endline database
			qui: merge 1:m manzana_code using "data/survey_endline.dta"
			drop _merge
			
	//- Run regressions 
			qui: reg `var' i.treatment_ri i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
			
			* Store coefficients in matrix
			matrix treat_effects[`n', 1] = _b[1.treatment_ri]
			matrix treat_effects[`n', 2] = _b[2.treatment_ri]
}

* Turn ATEs into variables
	
	clear	
	
	svmat treat_effects, names(col)
	
	save "data/rand_inf/RI_table_A13_`var'.dta", replace
	
}

	
//-------//
//-- Run regressions for randomization inference (behavioral addition of endline data)
//-------//

* Run regressions

foreach var in num_report {
	
	di "*** REGRESSIONS WITH VARIABLE `var' ***"
	
	* Create empty matrix
	matrix treat_effects = J(10000, 2, .)
	matrix colnames treat_effects = treat_ef spillover_ef
	
	
	forvalues n = 1/10000{
	
			use "data/rand_inf/block_simulate_randomizations_p1.dta", clear
				
			*di "This is simulation number `n'"
		
	//- Obtain treatment status of each block 
			keep manzana treatment_ri_`n'
			rename treatment_ri_`n' treatment_ri
			
	//- Merge with endline database
			qui: merge 1:m manzana using "data/behavioral_data.dta", generate(new_merge)
			drop new_merge
			
	//- Run regressions 
			qui: reg `var' i.treatment_ri i.barrio_code ${blockdemovars} ${geovars} [pweight=iweight], ///
				baselevels
	
			
			* Store coefficients in matrix
			matrix treat_effects[`n', 1] = _b[1.treatment_ri]
			matrix treat_effects[`n', 2] = _b[2.treatment_ri]
}

* Turn ATEs into variables
	
	clear	
	
	svmat treat_effects, names(col)
	
	save "data/rand_inf/RI_table_A13_`var'.dta", replace
	
}

	   
//-------//
//-- Run regressions and store p-values 	 
//-------//	
			
//-- Define matrix for multiple hypothesis comparison. P-values. --//

	mat table1t = J(3,1,.)
	mat table1s = J(3,1,.)
	
	
//----//								 
//- Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear			
				

//-- Column 1 (perceptions of the police)	

	reg i_legitp  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitp  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store t3_1
	
	//- Store p-values
	mat table1t[1,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[1,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	
					 
//-- Column 2 (perceptions of the military)	

	reg i_legitm  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum i_legitm  if control==1 
	estadd scalar c_mean = r(mean), replace
	
	estimates store t3_2
	
	//- Store p-values
	mat table1t[2,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[2,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	

//----//								 
//- Regressions with behavioral addition of endline data	
//----//				
	
	use "data/behavioral_data.dta", clear	
	
	
//-- Column 3 (demand for the military)	

	reg num_report i.treatment i.barrio_code ${blockdemovars} ${geovars} [pweight = iweight], baselevels
	
	qui sum num_report  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store t3_3
	
	//- Store p-values
	mat table1t[3,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[3,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	

//-------//
//-- Apply lenient correction and Export 		 
//-------//

//-- Apply corrections 
	
	global t1vars i_legitp i_legitm num_report

	mat rownames table1t = $t1vars
	mat rownames table1s = $t1vars

	* Add corrected p-values

	* - BH q value (1995)
		bhcorr, mat(table1t) newname(pvalue) outmat(table1ta)
		bhcorr, mat(table1s) newname(pvalue) outmat(table1sa)

	* - BH q threshold
		bhcorralt, mat(table1t) newname(pvalue) fdr(0.1) outmat(table1tb)
		bhcorralt, mat(table1s) newname(pvalue) fdr(0.1) outmat(table1sb)

	* - Holms (1979)
		holmscorr, mat(table1t) newname(pvalue) fwer(0.1) outmat(table1tc)
		holmscorr, mat(table1s) newname(pvalue) fwer(0.1) outmat(table1sc)

							   
	//-- Add checkmark to the latex table 
	
	checkmark, outcomes(${t1vars}) mat1t(table1ta) mat1s(table1sa) ///
								   mat2t(table1tb) mat2s(table1sb) ///
								   mat3t(table1tc) mat3s(table1sc) ename(t3_)


//------//					 
// -- Export regressions without covariates 
//------//

//-- Store p-values from randomization inference (endline data)

loc n = 0	
foreach var in i_legitp i_legitm num_report {
	
	* Load data of simulations
	
	di "*** THIS IS COLUMN NUMBER `var' ***"
	
	use "data/rand_inf/RI_table_A13_`var'.dta", clear
	loc ++n
	
	
	* Restore estimates of each regression
	
	if `n' == 1 {
		estimates restore t3_1
	} 
	
	if `n' == 2 {
		estimates restore t3_2
	} 
	
	if `n' == 3 {
		estimates restore t3_3
	} 
	

	* P-value of treatment efffect

	count if abs(treat_ef) > abs(_b[1.treatment])
	estadd scalar p_val_treat =  `r(N)'/10000, replace
	
	* P-value of spillover effect

	count if abs(spillover_ef) > abs(_b[2.treatment])
	estadd scalar p_val_spillover =  `r(N)'/10000, replace
	
} 
	
		
//-- Export the regressions --//
	
	loc var1 `"\textbf{\shortstack{Perceptions of \\ police}}"'
	loc var2 `"\textbf{\shortstack{Perceptions of \\ military}}"'
	loc var3 `"\textbf{\shortstack{Demand for \\ military}}"'

	esttab t3_1 t3_2 t3_3 ///
		using "results\ITT_perceptions_demand_lenient.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment) ///
		stats(N r2 c_mean p_val_treat p_val_spillover qval qval2 text text1 text2 text3, fmt(0 3 3 3 3) labels("Observations" "\$R^2$" "Control mean" "RI p-value (treatment)" "RI p-value (spillover)" "qval-treatment" "qval-spillover" "BH-treatment" "BH-spillover" "Holm-treatment" "Holm-spillover")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{2}{c}{\textbf{Survey data}}		   							///
		   & \textbf{Behavioral data} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-3} \cline{4-4} \addlinespace			 											///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	

						
						
			//---------------------------------------------------------//
			//-- Table A14: ITT on turnout for right-wing candidates --//
			//	with RI p-values and multiple comparison correction    //
			//---------------------------------------------------------//

//-------//
//-- Run regressions for randomization inference (endline data)
//-------//


* Run regressions 

foreach var in political_ideology1  {
	
	di "*** REGRESSIONS WITH VARIABLE `var' ***"
	
	* Create empty matrix
	matrix treat_effects = J(10000, 2, .)
	matrix colnames treat_effects = treat_ef spillover_ef
	
	
	forvalues n = 1/10000{
	
			use "data/rand_inf/block_simulate_randomizations_p1.dta", clear
				
			*di "This is simulation number `n'"
		
	//- Obtain treatment status of each block 
			keep manzana treatment_ri_`n'
			rename treatment_ri_`n' treatment_ri
			rename manzana manzana_code
			
	//- Merge with endline database
			qui: merge 1:m manzana_code using "data/survey_endline.dta"	
			drop _merge
						
	//- Run regressions 
			qui: reg `var' i.treatment_ri i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
			* Store coefficients in matrix
			matrix treat_effects[`n', 1] = _b[1.treatment_ri]
			matrix treat_effects[`n', 2] = _b[2.treatment_ri]
}

* Turn ATEs into variables
	
	clear	
	
	svmat treat_effects, names(col)
	
	save "data/rand_inf/RI_table_A14_`var'.dta", replace
	
}

				
//-------//
//-- Run regressions and store p-values 	 
//-------//	
			
//-- Define matrix for multiple hypothesis comparison. P-values. --//

	mat table1t = J(1,1,.)
	mat table1s = J(1,1,.)
	
	
//----//								 
//- Regressions with endline data	
//----//				
				
//-- Load data (endline)
					
	use "data/survey_endline.dta", clear

	
//-- Column 1 (turnout for conservative candidates - all)	

	reg political_ideology1  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum political_ideology1  if treatment == 0
	estadd scalar c_mean = r(mean), replace	
	
	estimates store t5_1
	
	//- Store p-values
	mat table1t[1,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[1,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	

	
//-------//
//-- Apply lenient correction and Export 		 
//-------//

//-- Apply corrections: since there's only one variable in this table we can't apply 
// the lenient corrections.  
	
		
//------//					 
//-- Export tables without covariates 
//------//

//-- Store p-values from randomization inference (endline data)

loc n = 0	
foreach var in political_ideology1  {
	
	* Load data of simulations
	
	di "*** THIS IS COLUMN NUMBER `var' ***"
	
	use "data/rand_inf/RI_table_A14_`var'.dta", clear
	loc ++n
	
	
	* Restore estimates of each regression
	
	if `n' == 1 {
		estimates restore t5_1
	}  
	

	* P-value of treatment efffect

	count if abs(treat_ef) > abs(_b[1.treatment])
	estadd scalar p_val_treat =  `r(N)'/10000, replace
	
	* P-value of spillover effect

	count if abs(spillover_ef) > abs(_b[2.treatment])
	estadd scalar p_val_spillover =  `r(N)'/10000, replace
	
} 

		
//------//	
//-- Export regressions -original format
//------//
	
		loc p1 "All"
				
		esttab t5_1  ///
			using "results\ITT_turnout_lenient.tex", ///
			legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
			order(treatment spillover) compress ///
			indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
			keep(1.treatment 2.treatment) ///
			stats(N r2 c_mean p_val_treat p_val_spillover qval qval2 text text1 text2 text3, fmt(0 3 3 3 3) labels("Observations" "\$R^2$" "Control mean" "RI p-value (treatment)" "RI p-value (spillover)" "qval-treatment" "qval-spillover" "BH-treatment" "BH-spillover" "Holm-treatment" "Holm-spillover")) ///
			label nonotes nonum nodepvars nogaps mtitle(`"`p1'"') ///
			star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 ///
			prehead(  																		///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{1}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-2} \addlinespace			 											///
			&  \multicolumn{1}{c}{\textbf{\shortstack{Turnout for \\ conservative \\candidates}}}  \\			///
			\noalign{\smallskip}																	///
			\cline{2-2} \addlinespace													///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
	   	
	   
	   
				//---------------------------------------------------//
				//--   Table A15: ITT on support for vigilantism   --//
				// 		 and military coups with RI p-values and 	 //
				//			multiple comparisons correction 		 //
				//---------------------------------------------------//


//-------//
//-- Run regressions for randomization inference (endline data)
//-------//

* Run regressions

foreach var in attitudes_milicoup_crime attitudes_milicoup_corr ///
			attitudes_lawenforcement_std attitudes_commpunish_std {
	
	di "*** REGRESSIONS WITH VARIABLE `var' ***"
	
	* Create empty matrix
	matrix treat_effects = J(10000, 2, .)
	matrix colnames treat_effects = treat_ef spillover_ef
	
	
	forvalues n = 1/10000{
	
			use "data/rand_inf/block_simulate_randomizations_p1.dta", clear
				
			*di "This is simulation number `n'"
			
		
	//- Obtain treatment status of each block 
			keep manzana treatment_ri_`n'
			rename treatment_ri_`n' treatment_ri
			rename manzana manzana_code

	//- Merge with endline database
			qui: merge 1:m manzana_code using "data/survey_endline.dta"	
			drop _merge
						
	//- Run regressions 
			qui: reg `var' i.treatment_ri i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
			
			* Store coefficients in matrix
			matrix treat_effects[`n', 1] = _b[1.treatment_ri]
			matrix treat_effects[`n', 2] = _b[2.treatment_ri]
}

* Turn ATEs into variables
	
	clear	
	
	svmat treat_effects, names(col)
	
	save "data/rand_inf/RI_table_A15_`var'.dta", replace
	
}

				
//-------//
//-- Run regressions and store p-values 	 
//-------//	
			
//-- Define matrix for multiple hypothesis comparison. P-values. --//

	mat table1t = J(4,1,.)
	mat table1s = J(4,1,.)
	
				
//----//								 
//- Regressions with endline data	
//----//				
				
//-- Load data (endline)
					
	use "data/survey_endline.dta", clear
			

//-- Column 1 (supports military coups in response to crime)	

	reg attitudes_milicoup_crime  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_crime  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store t4_1
	
	//- Store p-values
	mat table1t[1,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[1,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	
	
//-- Column 2 (supports military coups in response to corruption)	

	reg attitudes_milicoup_corr  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_milicoup_corr  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store t4_2
	
	//- Store p-values
	mat table1t[2,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[2,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))


//-- Column 3 (survey support for vigilantism)	
		
	reg attitudes_lawenforcement_std  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_lawenforcement_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store t4_3

	//- Store p-values
	mat table1t[3,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[3,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	
		
//-- Column 4 (survey support for bypassing the police)

	reg attitudes_commpunish_std  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum attitudes_commpunish_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store t4_4
	
	//- Store p-values
	mat table1t[4,1] = 2*ttail(e(df_r), abs(_b[1.treatment]/_se[1.treatment]))
	mat table1s[4,1] = 2*ttail(e(df_r), abs(_b[2.treatment]/_se[2.treatment]))
	
	
//-------//
//-- Apply lenient correction and Export 		 
//-------//

//-- Apply corrections 
	
	global t1vars attitudes_milicoup_crime attitudes_milicoup_corr attitudes_lawenforcement_std attitudes_commpunish_std

	mat rownames table1t = $t1vars
	mat rownames table1s = $t1vars

	* Add corrected p-values

	* - BH q value (1995)
		bhcorr, mat(table1t) newname(pvalue) outmat(table1ta)
		bhcorr, mat(table1s) newname(pvalue) outmat(table1sa)

	* - BH q threshold
		bhcorralt, mat(table1t) newname(pvalue) fdr(0.1) outmat(table1tb)
		bhcorralt, mat(table1s) newname(pvalue) fdr(0.1) outmat(table1sb)

	* - Holms (1979)
		holmscorr, mat(table1t) newname(pvalue) fwer(0.1) outmat(table1tc)
		holmscorr, mat(table1s) newname(pvalue) fwer(0.1) outmat(table1sc)

							   
	//-- Add checkmark to the latex table 
	
	checkmark, outcomes(${t1vars}) mat1t(table1ta) mat1s(table1sa) ///
								   mat2t(table1tb) mat2s(table1sb) ///
								   mat3t(table1tc) mat3s(table1sc) ename(t4_)
								   
//------//					 
//-- Store p-values from randomization inference (endline data)
//------//

loc n = 0	
foreach var in attitudes_milicoup_crime attitudes_milicoup_corr /// 
				attitudes_lawenforcement_std attitudes_commpunish_std {
	
	* Load data of simulations
	
	di "*** THIS IS COLUMN NUMBER `var' ***"
	
	use "data/rand_inf/RI_table_A15_`var'.dta", clear
	loc ++n
	
	
	* Restore estimates of each regression
	
	if `n' == 1 {
		estimates restore t4_1
	} 
	
	if `n' == 2 {
		estimates restore t4_2
	} 
	
	if `n' == 3 {
		estimates restore t4_3
	} 
	
	if `n' == 4 {
		estimates restore t4_4
	} 
	

	* P-value of treatment efffect

	count if abs(treat_ef) > abs(_b[1.treatment])
	estadd scalar p_val_treat =  `r(N)'/10000, replace
	
	* P-value of spillover effect

	count if abs(spillover_ef) > abs(_b[2.treatment])
	estadd scalar p_val_spillover =  `r(N)'/10000, replace
	
} 
				
				
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{In response \\ to crime}}"
	loc var2 "\textbf{\shortstack{In response \\ to corruption}}"
	loc var3 "\textbf{\shortstack{Bypassing the\\ legal system}}"
	loc var4 "\textbf{\shortstack{Bypassing the \\ police}}"

	esttab t4_1 t4_2 t4_3 t4_4 ///
		using "results\ITT_vigilante_coups_lenient.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment) ///
		stats(N r2 c_mean p_val_treat p_val_spillover qval qval2 text text1 text2 text3, fmt(0 3 3 3 3) labels("Observations" "\$R^2$" "Control mean" "RI p-value (treatment)" "RI p-value (spillover)" "qval-treatment" "qval-spillover" "BH-treatment" "BH-spillover" "Holm-treatment" "Holm-spillover")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"' `"`var4'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{4}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///
			\cline{2-5} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for military coups}}}		///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Support for vigilantism}}}  \\			///
			\cline{2-3} \cline{4-5} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
	  


	
			//---------------------------------------------------------//
			//-- Table A16: Treatment effects on crime, victimization --//
			//     crime witnessing, and perceptions of safety 		   //
			//---------------------------------------------------------//

//------//
//-- Regression with pre-strike admin data 
//------//

	//- Load data pre-strike (during the intervention)
	
	use "data/admin_data_during.dta", clear
	
	
	//-- Column 1 : crime index during intervention 

	reg unw_crime2_num  i.treatment /// 
		i.barrio_code $geovars $blockdemovars cum_all_unw_crime2_num [pweight=iweight]
	
	qui sum unw_crime2_num if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store UCP_noInt
	
	
//------//
//-- Regression with post-strike admin data 
//------//

	//- Load data post strike (after the intervention)
	
	use "data/admin_data_after.dta", clear
	

	//- Column 2: crime index after intervention

	reg unw_crime_num  i.treatment /// 
		i.barrio_code $geovars $blockdemovars cum_all_unw_crime_num [pweight=iweight]
	
	qui sum unw_crime_num if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store AdminShort2020_unw

	
//------//
//-- Regression with endline data
//------//

	//- Cargo datos del endline survey

	use "data/survey_endline.dta", clear

	
	//-- Column 3: Crime victimization during intervention

	reg i2_victimduringindex_std  i.treatment /// 
			i.barrio_code ${demovars} ${geovars}  [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
	qui sum i2_victimduringindex_std if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store c_dur

					 
	//-- Column 4: Crime victimization  after intervention
	
	reg i2_victimafterindex_std  i.treatment /// 
			i.barrio_code ${demovars} ${geovars}  [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
	qui sum i2_victimafterindex_std if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store c_pos
	
	
	//-- Column 5: Crime witnessing after intervention 

	reg i_witnessindex_std  i.treatment /// 
			i.barrio_code ${demovars} ${geovars}  [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
	qui sum i_witnessindex_std if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store w_pos
	
	
	//-- Column 6: Safety perceptions overall
	
	reg i_securityallindex_std  i.treatment /// 
			i.barrio_code ${demovars} ${geovars}  [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
	qui sum i_securityallindex_std if treatment ==0
	estadd scalar c_mean = r(mean), replace
	
	estadd matrix table = r(table)
	estimates store safety
	
	
//-- Export the regressions without controls --//
	
	loc var1 `"\textbf{\shortstack{During \\ intervention}}"'
	loc var2 `"\textbf{\shortstack{After \\ intervention}}"'
	loc var3 `"\textbf{\shortstack{During \\ intervention}}"'
	loc var4 `"\textbf{\shortstack{After \\ intervention}}"'
	loc var5 `"\textbf{\shortstack{After \\ intervention}}"'
	loc var6 `"\textbf{\shortstack{After \\ intervention}}"'
	
	   esttab UCP_noInt AdminShort2020_unw c_dur c_pos w_pos safety ///
		using "results\ITT_crime_vic_wit_safety.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		label keep(1.treatment 2.treatment) ///
		indicate("Individual controls = ${demovars}" "Neighborhood FE = *.barrio_code*" "Block-level controls = ${geovars}" , labels("\checkmark" "\xmark")) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"' `"`var4'"' `"`var5'"' `"`var6'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	///
		prehead( 													///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}				///
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}}    	/// 
		   \hline \hline    				   						///
		   \noalign{\smallskip} 									///
		   &  \multicolumn{2}{c}{\textbf{Admin data}} &  \multicolumn{3}{c}{\textbf{Survey data}} \\ ///
		   \cline{2-3} \cline{4-7} \addlinespace							///
		   &  \multicolumn{2}{c}{\textbf{Crime incidence}} & 				///
			  \multicolumn{2}{c}{\textbf{Crime victimization}} &			///
			  \multicolumn{1}{c}{\textbf{Crime witnessing}} &				///
			  \multicolumn{1}{c}{\textbf{Safety perceptions}} \\			///
			  \noalign{\smallskip}									///
			  \cline{2-3} \cline{4-5} \cline{6-6} \cline{7-7} \addlinespace								///		   
	   \noalign{\smallskip}											///
	   )  															///
	   posthead(\addlinespace 										///
			\hline 													///
			\addlinespace											///
		) 															///
	   postfoot(  													///
		  \noalign{\smallskip} \hline \hline  						///
		  \end{tabular} 											///
		  \medskip     												///
	   )	  
					

		
			//--------------------------------------------------------//
			//--  Table A17. Treatment effects on bribe-seeking and --// 
			//  human rights abuses by the police and the military    //
			//--------------------------------------------------------//	

//----//								 
//- Bribe - Regressions with monitoring data	
//----//
	
	use "data/survey_monitoring.dta"

//-- Column 1 (police asking for bribe - dummy)	
	
	reg d_corruption_police  i.treatment i.barrio_code ${indiv_control} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_corruption_police  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store poli_bribe_moni
	
	
//-- Column 2 (military asking for bribe - dummy)	
	
	reg d_corruption_military i.treatment i.barrio_code ${indiv_control} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_corruption_military  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store mili_bribe_moni
	
	
//----//								 
//- Bribe - Regressions with endline data	
//----//				
				
//- Load data (endline)
					
	use "data/survey_endline.dta", clear

	
//-- Column 3 (police asking for bribe - dummy)	
	
	reg corruption_police  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum corruption_police  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store poli_bribe
	
	
//-- Column 4 (military asking for bribe - dummy)	
	
	reg corruption_military i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum corruption_military  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store mili_bribe

	
//----//								 
//- Abuses - Regressions with monitoring data	
//----//
	
	use "data/survey_monitoring.dta", clear

//-- Column 5 (abuses by the police)	
					
	reg abuse_police  i.treatment i.barrio_code ${geovars} ${indiv_control} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum abuse_police  if treatment == 0
	estadd scalar c_mean = r(mean), replace 
	
	estimates store poli_abuse_moni,  title("Police")
	
	
//-- Column 6 (abuses by the military)

	reg abuse_military  i.treatment i.barrio_code ${geovars} ${indiv_control} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum abuse_military  if treatment == 0
	estadd scalar c_mean = r(mean), replace 
	
	estimates store mili_abuse_moni,  title("Military")
	

//----//								 
//- Abuses - Regressions with endline data	
//----//

	use "data/survey_endline.dta", clear	
	
	
//-- Column 7 (abuses by the police)

	reg abuse_police  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum abuse_police  if control==1 
	estadd scalar c_mean = r(mean), replace 
	
	estimates store poli_abuse,  title("Police")
	
		
//-- Column 8 (military abuse)

	reg abuse_military  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
			vce(cluster manzana_code) baselevels
	
	qui sum abuse_military  if control==1 
	estadd scalar c_mean = r(mean), replace 
	
	estimates store mili_abuse,  title("Military")
	
	
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{Police}}"
	loc var2 "\textbf{\shortstack{Military}}"
	loc var3 "\textbf{\shortstack{Police}}"
	loc var4 "\textbf{\shortstack{Military}}"
	loc var5 "\textbf{\shortstack{Police}}"
	loc var6 "\textbf{\shortstack{Military}}"
	loc var7 "\textbf{\shortstack{Police}}"
	loc var8 "\textbf{\shortstack{Military}}"

	esttab poli_bribe_moni mili_bribe_moni poli_bribe mili_bribe poli_abuse_moni mili_abuse_moni poli_abuse mili_abuse ///
		using "results\ITT_bribe_abuse_poli_mili.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var3'"' `"`var4'"' `"`var5'"' `"`var6'"' `"`var7'"' `"`var8'"')  ///
		star(\textsuperscript{\textdagger}  0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{4}{c}{\textbf{Bribe-seeking}} & \multicolumn{4}{c}{\textbf{Abuse}} \\ 									///
			\noalign{\smallskip}															///
			\cline{2-5} \cline{6-9} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Monitoring survey}}}		///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Endline survey}}} ///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Monitoring survey}}}		///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Endline survey}}} \\			///
			\cline{2-3} \cline{4-5} \cline{6-7} \cline{8-9} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	


					
				//---------------------------------------------------//
				//--  Table A18. ITT police/military perceptions  -- //
				//		of efficacy, abusiveness and fairness		 //
				//---------------------------------------------------//	
	

//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
		

//------//
//-- Regressions on police perceptions 
//------//	
	
//-- Run regressions 
	
	global attipolimili i_poliefficacy i_miliefficacy /// 
						i_poliabuse i_miliabuse /// 
						i_polifair i_milifair 
	
	loc j = 1

	foreach var in $attipolimili{
		di "*** REGRESSIONS WITH VARIABLE `var' ***"
		
		reg `var' i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
				vce(cluster manzana_code) baselevels
						
		qui sum `var' if treatment==0 
		estadd scalar c_mean = r(mean), replace
		estimates store attpol`j'
		
		loc ++j	
	}
	
	
		
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{Police}}"
	loc var2 "\textbf{\shortstack{Military}}"
	
	esttab attpol1 attpol2 attpol3 attpol4 attpol5 attpol6 ///
		using "results\ITT_efficacy_abuse_fair.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var1'"' `"`var2'"' `"`var1'"' `"`var2'"')  ///
		star(\textsuperscript{\textdagger}  0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{6}{c}{\textbf{Perception indeces}} \\ 									///
			\noalign{\smallskip}															///
			\cline{2-7} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Efficacy}}} 	///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Abusiveness}}}  /// 
			&  \multicolumn{2}{c}{\textbf{\shortstack{Fairness}}} \\			///
			\cline{2-3} \cline{4-5} \cline{6-7} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
	

	
				//-----------------------------------------------------//
				//--  	Table A19: Treatment effects on approval of  --//
				//--   	  and participation in left-wing protests    --//
				//-----------------------------------------------------//
				
//----//								 
//- Regressions with endline data	
//----//				
					
	use "data/survey_endline.dta", clear	
	
	
//-- Column 1 (attitudes towards protests - approves)
	
	reg strike_general_approval_std  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum strike_general_approval_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store str_approv
	
	
//-- Column 2 (attitudes towards protests - participated)

	reg strike_participation  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum strike_participation  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store str_partic

	
//-- Column 3 (approves of the military's attitude toward the protests)
 
	reg strike_military_approval_std  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum strike_military_approval_std  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store str_approv_mili 
	


//------//	
//-- Export regressions -original format
//------//
	
		loc p1 "Approves"
		loc p2 "Participated"
		loc p3 "\shortstack{Approves of\\the Military's \\ Response}"
				
		esttab str_approv str_partic str_approv_mili ///
			using "results\ITT_protests.tex", ///
			legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
			order(treatment spillover) compress ///
			indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
			keep(1.treatment 2.treatment) ///
			stats(N r2 c_mean, fmt(0 3 3 3 3) labels("Observations" "\$R^2$" "Control mean")) ///
			label nonotes nonum nodepvars nogaps mtitle(`"`p1'"' `"`p2'"' `"`p3'"') ///
			star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 ///
			prehead(  																		///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{3}{c}{\textbf{Survey data}} \\ 									///
			\noalign{\smallskip}															///			   						
			\cline{2-4} \addlinespace			 											///
			& \multicolumn{3}{c}{\textbf{\shortstack{Attitudes and behavior towards protests}}}  \\			///
			\noalign{\smallskip}																	///
			\cline{2-4}\addlinespace													///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )		
	

				//---------------------------------------------------//
				//--  Table A20. ITT police/military perceptions  -- //
				//			of corruption and excessive force		 //
				//---------------------------------------------------//	
	   
//- Load data (endline)
					
	use "data/survey_endline.dta", clear	
	
		
//-- Column 1 (dummy perceptions of police corruption)	
	
	reg d_attitudes_corrupt_police  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_attitudes_corrupt_police  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store poli_corr_d
					
					
//-- Column 2 (dummy perceptions of military corruption)	
	
	reg d_attitudes_corrupt_military  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_attitudes_corrupt_military  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store mili_corr_d
	
	
//-- Column 3 (dummy perceptions of police excessive force)	
	
	reg d_attitudes_excessive_police  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_attitudes_excessive_police  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store poli_abuse_d
					
					
//-- Column 4 (dummy perceptions of military excessive force)	
	
	reg d_attitudes_excessive_military  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
	
	qui sum d_attitudes_excessive_military  if treatment == 0
	estadd scalar c_mean = r(mean), replace
	
	estimates store mili_abuse_d	
	
	
//-- Export the regressions --//
	
	loc var1 "\textbf{\shortstack{Police}}"
	loc var2 "\textbf{\shortstack{Military}}"

	esttab poli_corr_d mili_corr_d poli_abuse_d mili_abuse_d ///
		using "results\ITT_corrupt_perc_poli_mili.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) compress ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///					
		keep(1.treatment 2.treatment) ///
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvar nogaps mtitle(`"`var1'"' `"`var2'"' `"`var1'"' `"`var2'"')  ///
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)								///
		prehead(  																			///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}										///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 								/// 
		   \hline \hline                                    								///
			\noalign{\smallskip}															///			   
		   & \multicolumn{4}{c}{\textbf{Perceptions of police and military}} \\ 			///
			\noalign{\smallskip}															///
			\cline{2-3} \cline{4-5} \addlinespace			 											///
			&  \multicolumn{2}{c}{\textbf{\shortstack{Corruption}}} &  \multicolumn{2}{c}{\textbf{\shortstack{Excessive force}}} \\	///
			\cline{2-3} \cline{4-5} \addlinespace	///
	   )  																							///
	   posthead(\addlinespace									///
			\hline												///
			\addlinespace										///
	   )		 												///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular} 										///
		  \medskip     											///
	   )	
	   
	   
				//-------------------------------------------------//
				//--  		Table A21. ITT on support for   	-- //
				//				retributive justice		 		   //
				//-------------------------------------------------//	

//----//								 
//- Regressions with endline data	
//----//

	use "data/survey_endline.dta", clear	

//-- Column 1 	

	reg justiceatt_stdindex  i.treatment i.barrio_code ${demovars} ${geovars} [pweight=iweight], ///
		vce(cluster manzana_code) baselevels
		
	qui sum justiceatt_stdindex  if control==1 
	estadd scalar c_mean = r(mean), replace 
	
	estimates store just


//----//								 
//- Export regressions 	
//----//

	loc var1 `"\textbf{\shortstack{Support for \\ retributive \\ justice }}"'
	
	esttab just ///
		using "results\ITT_retributive.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
		keep(1.treatment 2.treatment) /// 
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control mean")) ///
		label nonotes nonum nodepvars nogaps mtitle(`"`var1'"') /// 
		star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 ///
		prehead(  												///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}			///
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 	/// 
		   \hline \hline     									///
		   \noalign{\smallskip}									///
		   & \multicolumn{1}{c}{\textbf{Survey data}} \\ 		///
			\cline{2-2} \addlinespace					 		///
	   )  														///
	   posthead(\addlinespace 									///
			\hline 												///
			\addlinespace										///
		) 														///
	   postfoot(  												///
		  \noalign{\smallskip} \hline \hline  					///
		  \end{tabular}											///
		  \medskip    											///
	   )		
		   
	   

				//------------------------------------------------//
				//--   Table A22. ITT police/military presence  --//
				//					and arrests 			   	  //
				//------------------------------------------------//
				
//-----//
//-- Regressions with monitoring data (during intervention)
//-----//

	use "data/survey_monitoring.dta", clear		
		
				
//- Seen police/military on the block 
		
	reg d_seen_police i.treatment ///
				i.barrio_code $geovars $indiv_control [pweight=iweight], vce(cluster manzana_code)
		
		sum d_seen_police  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store poli_seen,  title("Police")
	
	
	reg d_seen_military i.treatment ///
				i.barrio_code $geovars $indiv_control [pweight=iweight], vce(cluster manzana_code)
		
		sum d_seen_military  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store mili_seen,  title("Military")
	
  
//- Seen police/military making arrests 
	
	reg d_arresting_police i.treatment 	///
			i.barrio_code $geovars $indiv_control [pweight = iweight], vce(cluster manzana_code)
		
		sum d_arresting_police  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store poli_arrest, title("Police")
	
	
	reg d_arresting_military i.treatment 	///
			i.barrio_code $geovars $indiv_control [pweight = iweight], vce(cluster manzana_code)
		
		sum d_arresting_military  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store mili_arrest, title("Military")
			   
			
			
//-----//
//-- Regressions with survey data (after intervention)
//-----//

//-- Load data on survey data 

	use "data/survey_endline.dta", clear		
	
	
 //- Seen police/military on the block
		
	reg d_seen_p i.treatment ///
				i.barrio_code ${demovars} ${geovars} [pweight=iweight], vce(cluster manzana_code) baselevels
		
		sum d_seen_p  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store compl_poli,  title("Police")
	
	
	reg d_seen_m i.treatment ///
				i.barrio_code ${demovars} ${geovars} [pweight=iweight], vce(cluster manzana_code) baselevels
		
		sum d_seen_m  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store compl_mili,  title("Military")
		
	 				

//- Seen police/military making arrests 	
		
	reg d_arresting_p i.treatment ///
				i.barrio_code ${demovars} ${geovars} [pweight=iweight], vce(cluster manzana_code) baselevels
		
		sum d_arresting_p  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store poli_arrest_aft,  title("Police")
	
	
	reg d_arresting_m i.treatment ///
				i.barrio_code ${demovars} ${geovars} [pweight=iweight], vce(cluster manzana_code) baselevels
		
		sum d_arresting_m  if treatment == 0
		estadd scalar c_mean = r(mean), replace
		
		estimates store mili_arrest_aft,  title("Military")
		

//------//	
//-- Export regressions -original format
//------//

	esttab poli_seen mili_seen poli_arrest mili_arrest compl_poli compl_mili poli_arrest_aft  mili_arrest_aft ///
		using "results\ITT_presence_arrests.tex", ///
		legend booktabs f replace b(%9.3fc) se(%9.3fc) ///
		order(1.treatment 2.treatment) ///
		indicate("Individual-level controls = ${demovars}" "Block-level controls = ${geovars}" "Neighborhood FE = *.barrio_code", labels("\checkmark" "\xmark")) ///
		keep(1.treatment 2.treatment) /// 
		stats(N r2 c_mean, fmt(0 3 3)  labels("Observations" "\$R^2$" "Control Mean"))  			///
		label nonotes nonum nodepvars nogaps star(\textsuperscript{\textdagger} 0.10 * 0.05 ** 0.01)	 						///
		prehead(  																					///
		   \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}			///				   
		   \begin{tabular}{@{\extracolsep{4pt}}l*{@M}{c}@{}} 										/// 
		   \hline \hline                                    										///
		   \noalign{\smallskip}																		///
		   & \multicolumn{4}{c}{\textbf{Monitoring data}}	    									///
		   & \multicolumn{4}{c}{\textbf{Survey data}} \\ 											///
			\cline{2-5} \cline{6-9} \addlinespace			 										///
		   \noalign{\smallskip}																		///
		   & \multicolumn{4}{c}{\textbf{During intervention}}	    									///
		   & \multicolumn{4}{c}{\textbf{After intervention}} \\ 											///
			\noalign{\smallskip}																	///
			\cline{2-5} \cline{6-9} \addlinespace			 										///
		   \noalign{\smallskip}																		///				   
		  & \multicolumn{2}{c}{\textbf{\shortstack{Seen on block}}} 						///
		   & \multicolumn{2}{c}{\textbf{\shortstack{Seen making \\ arrests}}} 							///
		   & \multicolumn{2}{c}{\textbf{\shortstack{Seen on block}}} 				///				   
		   & \multicolumn{2}{c}{\textbf{\shortstack{Seen making \\ arrests}}}  \\				///
			\noalign{\smallskip}																	///
		   \cline{2-3} \cline{4-5} \cline{6-7} \cline{8-9} \addlinespace ///              
		)  																							///
		posthead(\addlinespace 																		///
			\hline 																					///
			\addlinespace																			///
		) 																							///
		postfoot(  																					///
		  \noalign{\smallskip} \hline \hline  														///
		  \end{tabular}																				///
		  \medskip    																				///
		)					   

		


			//--------------------------------------------------------//
			//   Figure A1: Treatment effects on perceptions of the   //
			// 	  police and military using conjoint experiment,      //
			//			collapsing spillover and control groups       //
			//--------------------------------------------------------//
				
	use "data/conjoint_data.dta", clear
	

//-- Conjoint experiment 
	
	reg conjoint_stdin $demovars $geovars treatment_d##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
		
						 		
//-- Make the coefplot (with p-values)
	
	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment_d 1.treatment_d $demovars $geovars) xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) 	
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment_d#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment_d#0.r_profile_gun = "{bf: Treatment status × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment_d#0.r_profile_uniform = "Control × police"
							  1.treatment_d#1.r_profile_uniform = "Treatment × military"
							  0.treatment_d#0.r_profile_gun = "Control × pistol"
							  1.treatment_d#1.r_profile_gun = "Treatment × rifle",
							  labsize(small)) 
					mlabel("{it:p} = " + string(@pval,"%9.3f"))	
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle) baselevels  
					xlabel(.2 .4 .6 .8 1. 1.2, nogrid) xscale(range(-0.05 1.2) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))					
					; 
			#delim cr			

graph export "results/conjoint_treat_d.pdf", replace	

				

	 
			//-------------------------------------------------------//
			//--   Figure A2: Heterogeneous treatment effects on   --//
			// 		perceptions of police and the military by        //
			//		number of  patrols using conjoing experiment   	 //
			//-------------------------------------------------------//
			
	use "data/conjoint_data.dta", clear
	
	
//-- Conjoint experiment 
		
	reg conjoint_stdin $demovars $geovars treatment##c.n_events##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
	
						 		
//-- Make the coefplot 
	
	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment 1.treatment 2.treatment n_events $demovars $geovars
					 0.treatment#c.n_events 1.treatment#c.n_events 2.treatment#c.n_events 
					 0.treatment#1.r_profile_uniform 
					 1.treatment#0.r_profile_uniform 
					 2.treatment#0.r_profile_uniform 
					 0.treatment#1.r_profile_gun 
					 1.treatment#0.r_profile_gun 
					 2.treatment#0.r_profile_gun
					 0.treatment#1.r_profile_uniform#c.n_events 
					 1.treatment#0.r_profile_uniform#c.n_events 
					 2.treatment#0.r_profile_uniform#c.n_events
					 0.treatment#1.r_profile_gun#c.n_events 
					 1.treatment#0.r_profile_gun#c.n_events 
					 2.treatment#0.r_profile_gun#c.n_events)   
					 xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) omitted baselevels 
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment#0.r_profile_gun = "{bf: Treatment status × weapon}"
							  0.r_profile_uniform#c.n_events = "{bf: Number of patrols × uniform}"
							  0.r_profile_gun#c.n_events = "{bf: Number of patrols × weapon}"
							  0.treatment#0.r_profile_uniform#c.n_events = "{bf: Treatment status × number of patrols × uniform}"
							  0.treatment#0.r_profile_gun#c.n_events = "{bf: Treatment status × number of patrols × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment#0.r_profile_uniform = "Control × police"
							  1.treatment#1.r_profile_uniform = "Treatment × military"
							  2.treatment#1.r_profile_uniform = "Spillover × military"
							  0.treatment#0.r_profile_gun = "Control × pistol"
							  1.treatment#1.r_profile_gun = "Treatment × rifle"
							  2.treatment#1.r_profile_gun = "Spillover × rifle"
							  0.r_profile_uniform#c.n_events = "Number of patrols × police"
							  1.r_profile_uniform#c.n_events = "Number of patrols × military"
							  0.r_profile_gun#c.n_events = "Number of patrols × pistol "
							  1.r_profile_gun#c.n_events = "Number of patrols × rifle"
							  0.treatment#0.r_profile_uniform#c.n_events = "Control × number of patrols × police"
							  1.treatment#1.r_profile_uniform#c.n_events = "Treatment × number of patrols × military"
							  2.treatment#1.r_profile_uniform#c.n_events = "Spillover × number of patrols × military"
							  0.treatment#0.r_profile_gun#c.n_events = "Control × number of patrols × pistol"
							  1.treatment#1.r_profile_gun#c.n_events = "Treatment × number of patrols × rifle"
							  2.treatment#1.r_profile_gun#c.n_events = "Spillover × number of patrols × rifle",
							  labsize(small)) 		
					mlabel("{it:p} = " + string(@pval,"%9.3f"))	mlabsize(4)
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle)
					xlabel(-.4 -.2 0 .2 .4 .6 .8 1. 1.2, nogrid) xscale(range(-0.4 1.25) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))	
		; 
	#delim cr			 

graph export "results/conjoint_het_num_patrols.pdf", replace	


			  	   
				//------------------------------------------------//
				//--  Figure A3: Treatment effects on feelings  --//
				// 	    of safety using conjoint experiment	   	  //
				//------------------------------------------------//
				
	use "data/conjoint_data.dta", clear
	
	
//-- Conjoint experiment 
		
	reg cojoint_safer $demovars $geovars treatment##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
	
		 
//-- Coefplot of all regressions 

	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment 1.treatment 2.treatment $demovars $geovars) xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) 	
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment#0.r_profile_gun = "{bf: Treatment status × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment#0.r_profile_uniform = "Control × police"
							  1.treatment#1.r_profile_uniform = "Treatment × military"
							  2.treatment#1.r_profile_uniform = "Spillover × military"
							  0.treatment#0.r_profile_gun = "Control × pistol"
							  1.treatment#1.r_profile_gun = "Treatment × rifle"
							  2.treatment#1.r_profile_gun = "Spillover × rifle",
							  labsize(small)) 
					mlabel("{it:p} = " + string(@pval,"%9.3f"))			  
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle) baselevels  
					xlabel(.1 .2 .3 .4 .5, nogrid) xscale(range(-0.05 0.5) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))					
					; 
			#delim cr			

graph export "results/conjoint_safe.pdf", replace			



				//--------------------------------------------------//
				//--   Figure A4: Treatment effects on capacity   --//
				// 	   to deter crime using conjoint experiment	 	//
				//--------------------------------------------------//
				
	use "data/conjoint_data.dta", clear
	
	
//-- Conjoint experiment 
		
	reg cojoint_detercrime $demovars $geovars treatment##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
	
		 
//-- Coefplot of all regressions (without p-values)
	
	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment 1.treatment 2.treatment $demovars $geovars) xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) 	
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment#0.r_profile_gun = "{bf: Treatment status × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment#0.r_profile_uniform = "Control × police"
							  1.treatment#1.r_profile_uniform = "Treatment × military"
							  2.treatment#1.r_profile_uniform = "Spillover × military"
							  0.treatment#0.r_profile_gun = "Control × pistol"
							  1.treatment#1.r_profile_gun = "Treatment × rifle"
							  2.treatment#1.r_profile_gun = "Spillover × rifle",
							  labsize(small)) 
					mlabel("{it:p} = " + string(@pval,"%9.3f"))		  
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle) baselevels  
					xlabel(.1 .2 .3 .4 , nogrid) xscale(range(-0.05 0.4) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))					
					; 
			#delim cr			

graph export "results/conjoint_deter.pdf", replace			


				//-----------------------------------------------------//
				//-- Figure A5: treatment effects on perceptions of  --//
				// 		 abusiveness using conjoint experiment	   	   //
				//-----------------------------------------------------//
				
	use "data/conjoint_data.dta", clear
	
	
//-- Conjoint experiment 
		
	reg cojoint_abuse $demovars $geovars treatment##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
	
		 
//-- Coefplot of all regressions (without p-values)


	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment 1.treatment 2.treatment $demovars $geovars) xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) 	
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment#0.r_profile_gun = "{bf: Treatment status × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment#0.r_profile_uniform = "Control × police"
							  1.treatment#1.r_profile_uniform = "Treatment × military"
							  2.treatment#1.r_profile_uniform = "Spillover × military"
							  0.treatment#0.r_profile_gun = "Control × pistol"
							  1.treatment#1.r_profile_gun = "Treatment × rifle"
							  2.treatment#1.r_profile_gun = "Spillover × rifle",
							  labsize(small)) 
					mlabel("{it:p} = " + string(@pval,"%9.3f"))			  
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle) baselevels  
					xlabel(-.3 -.2 -.1 0 .1 .2, nogrid) xscale(range(-0.3 0.2) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))					
					; 
			#delim cr			

graph export "results/conjoint_abuse.pdf", replace			
				
				

			//------------------------------------------------------//
			//-- Figure A6: treatment effects on perceptions of   --//
			// 		 corruption using conjoint experiment	   		//
			//------------------------------------------------------//
				
	use "data/conjoint_data.dta", clear
	
	
//-- Conjoint experiment 
		
	reg cojoint_corruption $demovars $geovars treatment##(r_profile_u r_profile_g) ///
				 i.barrio_code [pweight = iweight], vce(cluster key) baselevels 
	
	estadd matrix table = r(table)
	eststo cjoint, title("Index")	
	
		 
//-- Coefplot of all regressions (without p-values)
	
	#delim ;				
	coefplot cjoint, bylab("Conjoint Index") || , 		
					 drop(*barrio* _cons 0.treatment 1.treatment 2.treatment $demovars $geovars) xline(0, lpattern(dash) lwidth(vthin) lcolor(black)) 	
					 headings(0.r_profile_uniform = "{bf: Uniform}" 
							  0.r_profile_gun = "{bf: Weapon}"
							  0.treatment#0.r_profile_uniform = "{bf: Treatment status × uniform}"
							  0.treatment#0.r_profile_gun = "{bf: Treatment status × weapon}",
							  labsize(small))
					coeflabel(0.r_profile_uniform = "Police"
							  1.r_profile_uniform = "Military" 
							  0.r_profile_gun = "Pistol"
							  1.r_profile_gun = "Rifle"
							  0.treatment#0.r_profile_uniform = "Control × police"
							  1.treatment#1.r_profile_uniform = "Treatment × military"
							  2.treatment#1.r_profile_uniform = "Spillover × military"
							  0.treatment#0.r_profile_gun = "Control × pistol"
							  1.treatment#1.r_profile_gun = "Treatment × rifle"
							  2.treatment#1.r_profile_gun = "Spillover × rifle",
							  labsize(small)) 
					mlabel("{it:p} = " + string(@pval,"%9.3f"))	
					xtitle("Average marginal component effect") scheme(plotplainblind) color(black)
					graphregion(fcolor(white)) ciopts(lcolor(black)) msize(small) msymbol(circle) baselevels  
					xlabel(-.6 -.4 -.2 0 .2, nogrid) xscale(range(-0.6 0.2) on extend) /// 
					ylabel(, nogrid) ///
					mlabcolor(none) addplot(scatter @at @ul, ms(i) mlabel(@mlbl) mlabcolor(black))					
					; 
			#delim cr			

graph export "results/conjoint_corrupt.pdf", replace			



